package com.ruicar.afs.cloud.account.common.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.ruicar.afs.cloud.account.enums.rules.AtomOperatorScopeType;
import com.ruicar.afs.cloud.account.vo.VoucherAtomVo;
import com.ruicar.afs.cloud.common.core.entity.BaseEntity;
import com.ruicar.afs.cloud.common.modules.contract.enums.AtomComponentType;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

@TableName("voucher_atom")
@Data
public class VoucherAtom extends BaseEntity {

    @NotBlank(message = "原子key不能为空")
    private String atomKey ;

    @NotBlank(message = "原子名称不能为空")
    private String atomName ;
    /** 可用操作符范围;all-所有
     cust-自定义 */
    @NotNull(message = "原子操作符范围不能为空")
    private AtomOperatorScopeType atomOperatorScope ;
    /** 取值表达式 */
    @NotBlank(message = "原子取值表达式不能为空")
    private String atomValueExpress ;

    @ApiModelProperty("原子类型")
    @NotNull(message = "原子类型不能为空")
    private AtomComponentType atomType ;

    private String deleteToken ;

    public static VoucherAtom convertFromVo(VoucherAtomVo vo){
        VoucherAtom voucherAtom = new VoucherAtom();
        voucherAtom.setAtomKey(vo.getAtomKey());
        voucherAtom.setAtomName(vo.getAtomName().trim());
        voucherAtom.setAtomOperatorScope(vo.getAtomOperatorScope());
        voucherAtom.setAtomValueExpress(vo.getAtomValueExpress().trim());
        voucherAtom.setAtomType(vo.getAtomType());
        return voucherAtom;
    }
}
